package org.nimi317.web_gis.scan;

import org.nimi317.web_gis.context.SecurityContextHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author thunderobot
 */
public class DivisionRegister implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        AnnotationAttributes annoAttrs = AnnotationAttributes.fromMap(importingClassMetadata
                .getAnnotationAttributes(org.nimi317.web_gis.annotation.DivisionScan.class.getName()));//获取@Import所标注的注解信息
        // AnnotationAttributes有获取各种注解信息的方法
        assert annoAttrs != null;
        SecurityContextHolder.setClassWithDivision(annoAttrs.getStringArray("value"));
        ImportBeanDefinitionRegistrar.super.registerBeanDefinitions(importingClassMetadata, registry);
    }
}
